import { ref } from 'vue'
import PageDialog from '@/components/page-dialog'

type CbFn = (item?: any) => void
export function usePageDialog(newCb?: CbFn, editCb?: CbFn) {
  const defaultInfo = ref<any>({})
  const pageDialogRef = ref<InstanceType<typeof PageDialog>>()
  const newPageData = () => {
    defaultInfo.value = {}
    if (pageDialogRef.value) {
      newCb && newCb()
      pageDialogRef.value.dialogVisible = true
    }
  }
  const editPageData = (item: any) => {
    defaultInfo.value = { ...item }
    if (pageDialogRef.value) {
      editCb && editCb(item)
      pageDialogRef.value.dialogVisible = true
    }
  }

  return [defaultInfo, pageDialogRef, newPageData, editPageData]
}
